package cn.thoughtworks.service.impl;

import cn.thoughtworks.model.Size;
import cn.thoughtworks.service.Verify;

/**
 *
 *
 * @author briarbear
 * @blog https://briarbear.github.io
 * @create 2018-07-27-15:41
 */
public class OutOfRange implements Verify {
    /**
     * 验证数字是否超出范围
     * @param size 道路网格大小
     * @param command 输入命令
     * @return 验证结果
     */
    public boolean verify(Size size, String command) {

        String[] arr1 = command.split(";");
        for (int i = 0; i < arr1.length; i++) {
            String[] arr2 = arr1[i].split(" ");
            for (int j = 0; j < arr2.length; j++) {
                String[] arr3 = arr2[j].split(",");
                if (!(Integer.valueOf(arr3[0]) >=0 && Integer.valueOf(arr3[0])<size.getRow()))
                    return false;
                if (!(Integer.valueOf(arr3[1]) >=0 && Integer.valueOf(arr3[1])<size.getCol()))
                    return false;
            }
        }
        return true;
    }


}
